#!/bin/bash

# 整理proto对接ros的文件，并提取到指定目录

set -e

echo "开始整理打包文件"

CRTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

PKG_NAME=ros1_protobuf_msg_bridge
MAKE_DEB_DIR=${CRTDIR}/../../deb
INSTALL_DIR=${CRTDIR}/../../deb/deb_package/opt/ros/melodic
DEVEL_DIR=${CRTDIR}/../../devel
WORK_DIR=${CRTDIR}/../

rm -rf ${INSTALL_DIR} 

mkdir -p ${INSTALL_DIR}
cp -rf ${DEVEL_DIR}/include ${INSTALL_DIR}/
find ${INSTALL_DIR}/include -type f -name '*.cc' -exec rm -f {} +

cp -rf ${DEVEL_DIR}/lib ${INSTALL_DIR}/
mkdir -p ${INSTALL_DIR}/share/${PKG_NAME}
cp -rf ${WORK_DIR}/${PKG_NAME}/proto/${PKG_NAME}/* ${INSTALL_DIR}/share/${PKG_NAME}/
cp -rf ${WORK_DIR}/${PKG_NAME}/package.xml ${INSTALL_DIR}/share/${PKG_NAME}/
find ${INSTALL_DIR}/lib -type f -name '*.pyc' -exec rm -f {} +

rm -rf ${INSTALL_DIR}/lib/ros1_protobuf_msg_bridge_test
rm -rf ${INSTALL_DIR}/lib/python2.7/dist-packages/ros1_protobuf_msg_bridge_test

echo "整理完成"


echo "开始打包"

cd ${MAKE_DEB_DIR}
/bin/bash ./make_deb.sh

echo "打包完成"
